<?php

require_once("/includes/mysql_connect.php");
$query = "SELECT * FROM fail ORDER BY fail_id DESC";
$result = @mysql_query($query);
$row = mysql_fetch_array($result);
$id = $row['fail_date'];
echo "<b>Ultima data: "; echo $id;
$row['fail_date'];
echo "</b><br><br>";
$paramenddate = date('Y-m-d');
echo $paramenddate;
echo "<br><p>para</p>";
echo "row fail date:".$row['fail_date']."<p>pana</p><br>";
echo $row['fail_id'];




function Duration($parambegindate, $paramenddate) {
    $begindate = strtotime($parambegindate);
    $enddate = strtotime($paramenddate);
    $diff = intval($enddate) - intval($begindate);                 
    $diffday = intval(floor($diff/86400));
    $modday = ($diff%86400);
    $diffhour = intval(floor($modday/3600));
    $diffminute = intval(floor(($modday%3600)/60));
    $diffsecond = ($modday%60);
    return round($diffday)." Day(s), ".round($diffhour)." Hour(s), ".round($diffminute,0)." Minute(s), ".round($diffsecond,0)." Second(s).";
  }

echo Duration($row['fail_date'], date('Y-m-d'));

?>

<?php if(isset($_POST["submitted"]))
			{
				require_once("/includes/mysql_connect.php");
				//Verifica existenta prenumelui
				if(stripslashes(trim($_POST["first_name"])))
				{
					$first_name = escape_data($_POST["first_name"]);
				}
				else
				{
					$first_name = FALSE;
					echo "<p><font color = 'red'>Prenumele este obligatoriu.</font></p>";
				}
				
				if ($first_name)
				{
						$query = "INSERT INTO fail (fail_date) VALUES (NOW() )";
						$result = mysql_query($query) or trigger_error("Query: $query\n<br>MySQL Error:" . mysql_error());
						
						if(mysql_affected_rows() == 1) 
						{//Daca rularea a decurs fara probleme.
		
							echo "<h3>Dont do it again.</h3>";
						}
						else
						{//Daca apar probleme
							echo "<p><font color='red'>Eroare de sistem. Nu ai putut fi inregistrat. Ne cerem scuze.</font></p>";
						}
					
					mysql_close();
				}
				}
					?>
            <form action="fail.php" method="post">
            <table>
            <tr>
            <td>Prenumele: </td><td><input type="text" name="first_name" size="20" value="<?php if(isset($_POST['first_name'])) echo $_POST['first_name'];?>"></td>
            </tr></table>
            <input type="submit" name="submit" value="fail!">
            <input type="hidden" name="submitted" value="TRUE"/>
            </form>
            